package com.luke.springcloud;

import com.luke.springcloud.config.MySelfRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @Descrtption RibbonRestServiceMain8090
 * @Author luke
 * @Date 2020/4/28
 **/
@SpringBootApplication
@EnableDiscoveryClient
@RibbonClient(name = "*",configuration = MySelfRule.class) //修改Ribbo负载均衡策略
public class RibbonRestServiceMain8090 {

    public static void main(String[] args) {
        SpringApplication.run(RibbonRestServiceMain8090.class,args);
    }

    @Bean
    @LoadBalanced //RestTemplate整合负载均衡器Ribbon
    RestTemplate restTemplate(){
        //参考：https://blog.csdn.net/heyiwuwu/article/details/103825042
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(5000);
        requestFactory.setReadTimeout(5000);
        return new RestTemplate(requestFactory);
    }

}
